home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / soft / development / Macromedia RoboHelp X5 / RoboHelpOffice.exe / Data1.cab / _444A8EF0AB5E4397A21551E5C291289F < prev    next >
Encoding:
Extensible Markup Language  |  2003-11-17  |  15.9 KB  |  413 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0"
  3.                 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  4.                 xmlns:roboml="urn:schemas-ehelp-com:xslt"
  5.                 xmlns:RHHandlerDb="http://ehelp.com/RHHandlerDb"
  6.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7.                 xmlns:html="http://www.w3.org/1999/xhtml"
  8.                 exclude-result-prefixes="roboml msxsl RHHandlerDb xsl html">
  9.  
  10. <xsl:output method="xml" encoding="utf-8" indent="yes"/>
  11.  
  12. <!-- parameters -->
  13. <xsl:param name="roboxml_source_file_name">safari.xml</xsl:param>
  14. <xsl:param name="roboxml_destination_file_name">aaa.xml</xsl:param>
  15. <xsl:param name="roboxml_source_dir_name">c:\\Tmp\\Sample\\_Output\\3\\</xsl:param>
  16. <xsl:param name="roboxml_destination_dir_name">c:\\Tmp\\Sample\\_Output\\3\\1\\</xsl:param>
  17. <xsl:param name="roboxml_progress_file_name">__status__.xml</xsl:param>
  18. <xsl:param name="roboxml_preserve_white_space">true</xsl:param>
  19. <xsl:param name="roboxml_resolve_externals">false</xsl:param>
  20. <xsl:param name="roboxml_language_name">English</xsl:param>
  21. <xsl:param name="export.comment">1</xsl:param>
  22. <xsl:param name="export.style">1</xsl:param>
  23. <xsl:param name="export.script">1</xsl:param>
  24.  
  25. <xsl:param name="cleanup.xhtmlfiles" select="0" />
  26. <!-- includings -->
  27. <xsl:include href="./common/rhc_l10n.xsl"/>        <!-- language -->
  28. <xsl:include href="PRJ2DOCBOOKUTILS.xsl"/>        <!-- utility template and script functions -->
  29.  
  30. <!-- ================= Script defines here =========================== -->
  31. <msxsl:script language="JScript" implements-prefix="RHHandlerDb">
  32.  
  33. function wellFormedPath( pathName, fileName )
  34. {
  35.     var regExp = new RegExp("/", "g");
  36.     var srcPath = pathName.replace(regExp, "\\") ;
  37.     
  38.     if (srcPath.length > 0)
  39.     {
  40.         if (srcPath.charAt(srcPath.length-1) != "\\") srcPath += "\\" ;
  41.     }
  42.     srcPath += fileName ;
  43.  
  44.     return srcPath.replace(regExp, "\\") ;
  45. }
  46.  
  47. function getTransformedURL( srcURL )
  48. {
  49.     var newURL = wellFormedPath("", srcURL) ;
  50.     var transURL = getXmlfilenameFromHtm ( newURL, "\\") ;
  51.  
  52.     var regExp = /\\/g ;
  53.     transURL = transURL.replace(regExp, "/") ;
  54.  
  55.     return transURL ;
  56. }
  57.  
  58. function updateProcessStatusFile(dstPath, progressfilename, strDoing, nTotalFiles, nCurrentFile)
  59. {
  60.     try
  61.     {
  62.         var strStatus ;
  63.         strStatus    = "<?xml version=\"1.0\" ?>" ;
  64.         strStatus    = strStatus + "<status><doing>" + strDoing + "</doing>" ;
  65.         strStatus    = strStatus + "<total>" + nTotalFiles + "</total>" ;
  66.         strStatus    = strStatus + "<current>" + nCurrentFile + "</current></status>" ;
  67.     
  68.         var fso        = new ActiveXObject("Scripting.FileSystemObject");
  69.         var fileName    = wellFormedPath(dstPath, progressfilename) ;
  70.         var pgsFile    = fso.CreateTextFile(fileName, true);
  71.     
  72.         pgsFile.WriteLine(strStatus);
  73.         pgsFile.Close();
  74.  
  75.     }
  76.     catch(e)
  77.     {
  78.         return "ERROR: " + e ;
  79.     }
  80.     return "" ;
  81. }
  82.  
  83. function rhcLangID_To_DocBookLangID(strRhcLangID)
  84. {
  85.     if(strRhcLangID == "English")                        return "en";
  86.     else if(strRhcLangID == "Dansk")                    return "da";
  87.     else if(strRhcLangID == "Deutsch")                    return "de";
  88.     else if(strRhcLangID == "Espa├▒ol")                    return "es";
  89.     else if(strRhcLangID == "Fran├ºais")                    return "fr";
  90.     else if(strRhcLangID == "Italiano")                    return "it";
  91.     else if(strRhcLangID == "Nederlands")                return "nl";
  92.     else if(strRhcLangID == "Norsk")                    return "no";    
  93.     else if(strRhcLangID == "Portugu├¬s(Brasil)")        return "pt_br";    
  94.     else if(strRhcLangID == "Portugu├¬s(Portugal)")        return "pt";
  95.     else if(strRhcLangID == "Svenska")                    return "sv";
  96.     return "en";    
  97. }
  98.  
  99. function xml2Docbook(dstPath, srcPath, xmldocname, xsldocname,
  100.         prjfilename, strTopicExportFlags, bPreserveWhiteSpace, bResolveExternals, strLanguage)
  101. {
  102.     try
  103.     {
  104.         var srcDocName    = wellFormedPath( srcPath, xmldocname ) ;
  105.         var prjDocName    = prjfilename ;        // prjfilename is a full-path filename
  106.         var dstDocName    = wellFormedPath( dstPath, xmldocname ) ;
  107.             dstDocName    = getXmlfilenameFromHtm( dstDocName, "\\") ;
  108.  
  109.         var xmldoc    = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
  110.         var xsldoc    = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
  111.         var output    = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
  112.         var xslt    = new ActiveXObject("Msxml2.XSLTemplate.4.0");
  113.  
  114.         xmldoc.preserveWhiteSpace = bPreserveWhiteSpace ;
  115.         output.preserveWhiteSpace = bPreserveWhiteSpace ;
  116.  
  117.         xmldoc.async        = false;
  118.         xmldoc.validateOnParse    = false;
  119.         xmldoc.resolveExternals = bResolveExternals;
  120.         xmldoc.load( srcDocName );
  121.     
  122.         xsldoc.async        = false;
  123.         xsldoc.validateOnParse    = false;
  124.         xsldoc.resolveExternals = bResolveExternals ;
  125.         xsldoc.load( xsldocname );
  126.  
  127.         xslt.stylesheet = xsldoc;
  128.  
  129.         var xslProc    = xslt.createProcessor();
  130.         xslProc.input    = xmldoc;
  131.         xslProc.output    = output;
  132.  
  133.         xslProc.addParameter("roboxml_destination_dir_name", wellFormedPath(dstPath,""));
  134.         xslProc.addParameter("roboxml_project_file_name", prjDocName);
  135.         xslProc.addParameter("rhc_language_name", rhcLangID_To_DocBookLangID(strLanguage));
  136.         
  137.  
  138.         if (strTopicExportFlags.length>=3)
  139.         {
  140.             xslProc.addParameter("export.comment", strTopicExportFlags.charAt(0));
  141.             xslProc.addParameter("export.script", strTopicExportFlags.charAt(1));
  142.             xslProc.addParameter("export.style", strTopicExportFlags.charAt(2));
  143.         }
  144.     
  145.         xslProc.transform();
  146.         output.save(dstDocName);
  147.     }
  148.     catch(e)
  149.     {
  150.         throw e ;
  151.         return "ERROR: " + e ;
  152.     }
  153.     return "" ;
  154. }
  155. </msxsl:script>
  156.  
  157. <!-- templates start here -->
  158.     <xsl:template match="/roboml">
  159.         <appendix>
  160.             <appendixinfo>
  161.                 <xsl:call-template name="generate_publisher_info">
  162.                     <xsl:with-param name="rootnode" select="." />
  163.                 </xsl:call-template>
  164.             </appendixinfo>
  165.  
  166.             <title>
  167.                 <xsl:variable name="projtitle">
  168.                     <xsl:call-template name="gentext">
  169.                         <xsl:with-param name="key" select="'rhc.template.prjtitle'"/>
  170.                         <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  171.                     </xsl:call-template>
  172.                 </xsl:variable>
  173.                 <xsl:value-of select="$projtitle" />
  174.             </title>
  175.  
  176.             <xsl:variable name="totalprojectfiles" select="count(project_files/*)" />
  177.             <xsl:variable name="totalfiles" select="count(./project_files/*|./topics/topic)" />
  178.             <xsl:call-template name="process_project_files">
  179.                 <xsl:with-param name="totalfiles" select="$totalfiles" />
  180.             </xsl:call-template>
  181.  
  182.             <xsl:call-template name="process_topics">
  183.                 <xsl:with-param name="totalfiles" select="$totalfiles" />
  184.                 <xsl:with-param name="totalprojectfiles" select="$totalprojectfiles" />
  185.             </xsl:call-template>
  186.  
  187.             <xsl:apply-templates select="comment()"/>
  188.  
  189.         </appendix>
  190.     </xsl:template>
  191.  
  192.     <xsl:template name="process_project_files">
  193.         <xsl:param name="totalfiles" select="1" />
  194.         <section>
  195.             <title>
  196.                 <xsl:call-template name="gentext">
  197.                     <xsl:with-param name="key" select="'rhc.projectfiles'" />
  198.                     <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  199.                 </xsl:call-template>
  200.             </title>
  201.             <itemizedlist>
  202.                 <xsl:for-each select="./project_files/*">
  203.                     <xsl:variable name="doing" select="concat('Transforming ', ./@url, ' ...')" />
  204.                     <xsl:variable name="current" select="position()" />
  205.                     <xsl:variable name="errMsg">
  206.                         <xsl:value-of select="RHHandlerDb:updateProcessStatusFile(string($roboxml_destination_dir_name),
  207.                             string($roboxml_progress_file_name), string($doing), string($totalfiles), string($current))" />
  208.                     </xsl:variable>            
  209.                     <xsl:if test="$errMsg != ''">
  210.                         <xsl:comment><xsl:value-of select="concat('Error occurs in writing progress data[', $errMsg, ']')"/></xsl:comment>
  211.                     </xsl:if>
  212.  
  213.                     <xsl:apply-templates select="." />
  214.                 </xsl:for-each>
  215.             </itemizedlist>
  216.         </section>
  217.     </xsl:template>
  218.     
  219.     <xsl:template name="process_topics">
  220.         <xsl:param name="totalfiles" select="1" />
  221.         <xsl:param name="totalprojectfiles" select="0" />
  222.         <section>
  223.             <title>
  224.                 <xsl:call-template name="gentext">
  225.                     <xsl:with-param name="key" select="'rhc.topicfiles'" />
  226.                     <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  227.                 </xsl:call-template>
  228.             </title>
  229.             <itemizedlist>
  230.                 <xsl:for-each select="./topics/topic">
  231.                     <xsl:variable name="doing" select="concat('Transforming topic ', @url, ' ...')" />
  232.                     <xsl:variable name="current" select="number($totalprojectfiles) + position()" />
  233.                     <xsl:variable name="errMsg">
  234.                         <xsl:value-of select="RHHandlerDb:updateProcessStatusFile(string($roboxml_destination_dir_name),
  235.                             string($roboxml_progress_file_name), string($doing), string($totalfiles), string($current))" />
  236.                     </xsl:variable>            
  237.                     <xsl:if test="$errMsg != ''">
  238.                         <xsl:comment><xsl:value-of select="concat('Error found while writing progress data[', $errMsg, ']')"/></xsl:comment>
  239.                     </xsl:if>
  240.  
  241.                     <xsl:apply-templates select="." />
  242.                 </xsl:for-each>
  243.             </itemizedlist>
  244.         </section>
  245.     </xsl:template>
  246.  
  247.     <xsl:template name="generate_file_url">
  248.         <xsl:param name="url" select="''" />
  249.         <xsl:param name="title" select="''" />
  250.  
  251.         <xsl:variable name="transformedURL">
  252.             <xsl:value-of select="RHHandlerDb:getTransformedURL(string($url))" />
  253.         </xsl:variable>
  254.         
  255.         <para>
  256.             <ulink>
  257.                 <xsl:attribute name="url">
  258.                     <xsl:value-of select="$transformedURL" />
  259.                 </xsl:attribute>
  260.                 <xsl:choose>
  261.                     <xsl:when test="normalize-space($title) != ''">
  262.                         <xsl:value-of select="$title" />
  263.                     </xsl:when>
  264.                     <xsl:otherwise>
  265.                         <xsl:value-of select="$transformedURL" />
  266.                     </xsl:otherwise>
  267.                 </xsl:choose>
  268.             </ulink>
  269.         </para>
  270.     </xsl:template>
  271.  
  272.     <xsl:template match="toc[normalize-space(@url)!= '']">
  273.         <listitem role="toc">
  274.             <xsl:variable name="errMsg">
  275.                 <xsl:value-of select="RHHandlerDb:xml2Docbook(string($roboxml_destination_dir_name),string($roboxml_source_dir_name),
  276.                             string(@url),'toc2docbook.xsl',string($roboxml_source_file_name),'',
  277.                             $roboxml_preserve_white_space, $roboxml_resolve_externals,string($roboxml_language_name))" />
  278.             </xsl:variable>
  279.             <xsl:if test="$errMsg != ''">
  280.                 <xsl:comment><xsl:value-of select="concat('Error occurs in transforming[', $errMsg, ']')"/></xsl:comment>
  281.             </xsl:if>
  282.             <xsl:call-template name="generate_file_url">
  283.                 <xsl:with-param name="url" select="@url" />
  284.                 <xsl:with-param name="title">
  285.                     <xsl:call-template name="gentext">
  286.                         <xsl:with-param name="key" select="'rhc.tableofcontents'" />
  287.                         <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  288.                     </xsl:call-template>
  289.                 </xsl:with-param>
  290.             </xsl:call-template>
  291.         </listitem>
  292.     </xsl:template>
  293.  
  294.     <!-- keyword index -->
  295.     <xsl:template match="index[normalize-space(@url)!= '' and @type='keyword']">
  296.         <listitem role="keyword">
  297.             <xsl:variable name="errMsg">
  298.                 <xsl:value-of select="RHHandlerDb:xml2Docbook(string($roboxml_destination_dir_name),string($roboxml_source_dir_name),
  299.                             string(@url),'index2docbook.xsl',string($roboxml_source_file_name),'',
  300.                             $roboxml_preserve_white_space, $roboxml_resolve_externals,string($roboxml_language_name))" />
  301.             </xsl:variable>
  302.             <xsl:if test="$errMsg != ''">
  303.                 <xsl:comment><xsl:value-of select="concat('Error occurs in transforming[', $errMsg, ']')"/></xsl:comment>
  304.             </xsl:if>
  305.             <xsl:call-template name="generate_file_url">
  306.                 <xsl:with-param name="url" select="@url" />
  307.                 <xsl:with-param name="title">
  308.                     <xsl:call-template name="gentext">
  309.                         <xsl:with-param name="key" select="'rhc.keywordindex'" />
  310.                         <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  311.                     </xsl:call-template>
  312.                 </xsl:with-param>
  313.             </xsl:call-template>
  314.         </listitem>
  315.     </xsl:template>
  316.  
  317.     <!-- see also index -->
  318.     <xsl:template match="index[normalize-space(@url)!= '' and @type='see also']">
  319.         <listitem role="seealso">
  320.             <xsl:variable name="errMsg">
  321.                 <xsl:value-of select="RHHandlerDb:xml2Docbook(string($roboxml_destination_dir_name),string($roboxml_source_dir_name),
  322.                             string(@url),'seealso2docbook.xsl',string($roboxml_source_file_name),'',
  323.                             $roboxml_preserve_white_space, $roboxml_resolve_externals,string($roboxml_language_name))" />
  324.             </xsl:variable>
  325.             <xsl:if test="$errMsg != ''">
  326.                 <xsl:comment><xsl:value-of select="concat('Error occurs in transforming[', $errMsg, ']')"/></xsl:comment>
  327.             </xsl:if>
  328.             <xsl:call-template name="generate_file_url">
  329.                 <xsl:with-param name="url" select="@url" />
  330.                 <xsl:with-param name="title">
  331.                     <xsl:call-template name="gentext">
  332.                         <xsl:with-param name="key" select="'rhc.seealsoindex'" />
  333.                         <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  334.                     </xsl:call-template>
  335.                 </xsl:with-param>
  336.             </xsl:call-template>
  337.         </listitem>
  338.     </xsl:template>
  339.  
  340.     <!-- glossary -->
  341.     <xsl:template match="gls[normalize-space(@url)!= '']">
  342.         <listitem role="gls">
  343.             <xsl:variable name="errMsg">
  344.                 <xsl:value-of select="RHHandlerDb:xml2Docbook(string($roboxml_destination_dir_name),string($roboxml_source_dir_name),
  345.                             string(@url),'glossary2docbook.xsl',string($roboxml_source_file_name),'',
  346.                             $roboxml_preserve_white_space, $roboxml_resolve_externals,string($roboxml_language_name))" />
  347.             </xsl:variable>
  348.             <xsl:if test="$errMsg != ''">
  349.                 <xsl:comment><xsl:value-of select="concat('Error occurs in transforming[', $errMsg, ']')"/></xsl:comment>
  350.             </xsl:if>
  351.  
  352.             <xsl:call-template name="generate_file_url">
  353.                 <xsl:with-param name="url" select="@url" />
  354.                 <xsl:with-param name="title">
  355.                     <xsl:call-template name="gentext">
  356.                         <xsl:with-param name="key" select="'rhc.glossary'" />
  357.                         <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  358.                     </xsl:call-template>
  359.                 </xsl:with-param>
  360.             </xsl:call-template>
  361.         </listitem>
  362.     </xsl:template>
  363.  
  364.     <!-- browse sequence -->
  365.     <xsl:template match="brs[normalize-space(@url)!= '']">
  366.         <listitem role="brs">
  367.             <xsl:variable name="errMsg">
  368.                 <xsl:value-of select="RHHandlerDb:xml2Docbook(string($roboxml_destination_dir_name),string($roboxml_source_dir_name),
  369.                             string(@url),'brs2docbook.xsl',string($roboxml_source_file_name),'',
  370.                             $roboxml_preserve_white_space, $roboxml_resolve_externals,string($roboxml_language_name))" />
  371.             </xsl:variable>
  372.             <xsl:if test="$errMsg != ''">
  373.                 <xsl:comment><xsl:value-of select="concat('Error occurs in transforming[', $errMsg, ']')"/></xsl:comment>
  374.             </xsl:if>
  375.             <xsl:call-template name="generate_file_url">
  376.                 <xsl:with-param name="url" select="@url" />
  377.                 <xsl:with-param name="title">
  378.                     <xsl:call-template name="gentext">
  379.                         <xsl:with-param name="key" select="'rhc.browsesequence'" />
  380.                         <xsl:with-param name="lang" select="RHHandlerDb:rhcLangID_To_DocBookLangID(string($roboxml_language_name))"/>
  381.                     </xsl:call-template>
  382.                 </xsl:with-param>
  383.             </xsl:call-template>
  384.         </listitem>
  385.     </xsl:template>
  386.  
  387.     <!-- topics -->
  388.     <xsl:template match="topic[normalize-space(@url)!= '']">
  389.         <xsl:variable name="TopicExportFlags">
  390.             <xsl:value-of select="concat($export.comment, $export.script, $export.style)"/>
  391.         </xsl:variable>
  392.         <listitem>
  393.             <xsl:variable name="errMsg">
  394.                 <xsl:value-of select="RHHandlerDb:xml2Docbook(string($roboxml_destination_dir_name),string($roboxml_source_dir_name),
  395.                             string(@url),'xhtml2docbook.xsl',string($roboxml_source_file_name), string($TopicExportFlags),
  396.                             $roboxml_preserve_white_space, $roboxml_resolve_externals,string($roboxml_language_name))" />
  397.             </xsl:variable>
  398.             <xsl:if test="$errMsg != ''">
  399.                 <xsl:comment><xsl:value-of select="concat('Error occurs in transforming[', $errMsg, ']')"/></xsl:comment>
  400.             </xsl:if>
  401.             <xsl:call-template name="generate_file_url">
  402.                 <xsl:with-param name="url" select="@url" />
  403.                 <xsl:with-param name="title" select="@title" />
  404.             </xsl:call-template>
  405.         </listitem>
  406.     </xsl:template>
  407.  
  408.     <xsl:template match="comment()">
  409.         <xsl:copy />
  410.     </xsl:template>
  411.  
  412. </xsl:stylesheet>
  413.